import httpRequest from '@/utils/hqqtRequest'

import type { AllRoleList, Records, allAllotAclList } from './type'

enum API {
    // 获取角色列表数据
    ROLE_LIST = '/admin/acl/role/',
    // 添加职位
    ADD_ROLE = '/admin/acl/role/save',
    // 修改职位
    PUT_ROLE = '/admin/acl/role/update',
    // 根据用户获取职位权限
    ALLOT_ACL = '/admin/acl/permission/toAssign/',
    // 分配权限
    ADD_ACL_ROLE = '/admin/acl/permission/doAssign?',
    // 删除职位
    DELETE_ACL = '/admin/acl/role/remove/'
}

export const getRoleListAPI = (page: number, limit: number, roleName: string) => httpRequest<any, AllRoleList>({ url: API.ROLE_LIST + `${page}/${limit}?roleName=${roleName}` })

export const changeRoleAPI = (data: Records) => {
    if (data.id) {
        return httpRequest<any, any>({ url: API.PUT_ROLE, method: 'PUT', data })
    } else {
        return httpRequest<any, any>({ url: API.ADD_ROLE, method: 'POST', data })
    }
}

export const getAllotAclAPI = (roleId: number | string) => httpRequest<any, allAllotAclList>({ url: API.ALLOT_ACL + roleId })

export const allotAclRoleAPI = (roleId: number, permissionId: number[]) => httpRequest<any, any>({ url: API.ADD_ACL_ROLE + `roleId=${roleId}&permissionId=${permissionId}`, method: 'POST' })

export const deleteAclAPI = (id: number | string) => httpRequest<any, any>({ url: API.DELETE_ACL + id,method: 'DELETE' })
